package combinereport.reportoperations.testcase;

import combinereport.reportoperations.Sum;

import dbmanager.DBManager;
import junit.framework.TestCase;
/**
 *testSum  This class is collection of a test cases which test the sum operation performed on specifed field.  
 * @author Sachin
 *
 */
public class testSum extends TestCase {
	public testSum(String name)
	{
		super(name);
	}
	/**
	 * testFirstSum() This method is used to test the sum operation which performed on a two integer value 
	 */
	public void testFirstSum()
	{	Sum s=new Sum();
		DBManager db=new DBManager();
		db.getConnect();
		s.setDatabase(db);
		s.setObject("10279");
		StringBuffer buffer1 =new StringBuffer("aaa\t200\naaa\t300\n");
		s.setHeading("item.item\titem.qty");
		s.setreporton("item");
		s.setbuffer(buffer1.toString().split("\n"));
		String expected[]={"aaa\t500.0"};
		s.getresult();
		String actual[] =s.getbuffer();
		System.out.println("**************************************************************************");
		System.out.println("The contents of expectedBuffer:: ");
	    System.out.println(expected.toString());
	    System.out.println("**************************************************************************");
	    System.out.println("The contents of actualbuffer:: ");
	    System.out.println(actual.toString()); 
	    System.out.println("**************************************************************************");
		for(int i=0;i<actual.length;i++)
		{	System.out.println(actual[i]);
			assertEquals(expected[i], actual[i]);
		}
	}
	/**
	 *testMinusValueSum() This method is used to test the sum operation which performed on a two negatve integer value 
	 */
	public void testMinusValueSum()
	{	Sum s=new Sum();
		DBManager db=new DBManager();
		db.getConnect();
		s.setDatabase(db);
		s.setObject("10279");
		StringBuffer buffer1 =new StringBuffer("aaa\t-21\nbbb\t-21\n");
		s.setHeading("item.item\titem.qty");
		s.setreporton("item");
		s.setbuffer(buffer1.toString().split("\n"));
		String expected[]={"aaa\t-42.0"};
		s.getresult();
		String actual[] =s.getbuffer();
		System.out.println("**************************************************************************");
		System.out.println("The contents of expectedBuffer:: ");
	    System.out.println(expected.toString());
	    System.out.println("**************************************************************************");
	    System.out.println("The contents of actualbuffer:: ");
	    System.out.println(actual.toString()); 
	    System.out.println("**************************************************************************");
		for(int i=0;i<actual.length;i++)
		{	System.out.println(actual[i]);
			assertEquals(expected[i], actual[i]);
		}
}
/**
 *testMinusPlusValueSum() This method is used to test the sum operation which performed on a negatve and positive integer value 
 */
	public void testMinusPlusValueSum()
	{	Sum s=new Sum();
		DBManager db=new DBManager();
		db.getConnect();
		s.setDatabase(db);
		s.setObject("10279");
		StringBuffer buffer1 =new StringBuffer("aaa\t21\nbbb\t-21\n");
		s.setHeading("item.item\titem.qty");
		s.setreporton("item");
		s.setbuffer(buffer1.toString().split("\n"));
		String expected[]={"aaa\t0.0"};
		s.getresult();
		String actual[] =s.getbuffer();
		System.out.println("**************************************************************************");
		System.out.println("The contents of expectedBuffer:: ");
	    System.out.println(expected.toString());
	    System.out.println("**************************************************************************");
	    System.out.println("The contents of actualbuffer:: ");
	    System.out.println(actual.toString()); 
	    System.out.println("**************************************************************************");
		for(int i=0;i<actual.length;i++)
		{	System.out.println(actual[i]);
			assertEquals(expected[i], actual[i]);
		}
	}
	/**
	 * testFloatValueSum() This method is used to test the sum operation which performed on a two float values value
	*/
	public void testFloatValueSum()
	{	Sum s=new Sum();
		DBManager db=new DBManager();
		db.getConnect();
		s.setDatabase(db);
		s.setObject("10279");
		StringBuffer buffer1 =new StringBuffer("aaa\t2.1\nbbb\t2.1\n");
		s.setHeading("item.item\titem.qty");
		s.setreporton("item");
		s.setbuffer(buffer1.toString().split("\n"));
		String expected[]={"aaa\t4.2"};
		s.getresult();
		String actual[] =s.getbuffer();
		System.out.println("**************************************************************************");
		System.out.println("The contents of expectedBuffer:: ");
	    System.out.println(expected.toString());
	    System.out.println("**************************************************************************");
	    System.out.println("The contents of actualbuffer:: ");
	    System.out.println(actual.toString()); 
	    System.out.println("**************************************************************************");
		for(int i=0;i<actual.length;i++)
		{	System.out.println(actual[i]);
			assertEquals(expected[i], actual[i]);
		}
	}
	/**
	 * testSpaceSum()  This method is used to test the sum operation which performed on a two integer values and the space is given befor specified field
	 */
	public void testSpaceSum()
	{	Sum s=new Sum();
		DBManager db=new DBManager();
		db.getConnect();
		s.setDatabase(db);
		s.setObject("10279");
		StringBuffer buffer1 =new StringBuffer("\t100\n\t100\n");
		s.setHeading("item.item\titem.qty");
		s.setreporton("item");
		s.setbuffer(buffer1.toString().split("\n"));
		String expected[]={"\t200.0"};
		s.getresult();
		String actual[] =s.getbuffer();
		for(int i=0;i<expected.length;i++)
		{
		System.out.println("**************************************************************************");
		System.out.println("The contents of expectedBuffer:: ");
	    System.out.println(expected.toString());
	    System.out.println("**************************************************************************");
	    System.out.println("The contents of actualbuffer:: ");
	    System.out.println(actual.toString()); 
	    System.out.println("**************************************************************************");
		}
		for(int i=0;i<actual.length;i++)
		{	System.out.println(actual[i]);
			assertEquals(expected[i], actual[i]);
		}
	}
	/**
	 * testFloatIntegerSum() This method is used to perform the sum operation on a both float and integer values
	 *
	 */
	public void testFloatIntegerSum()
	{	Sum s=new Sum();
		DBManager db=new DBManager();
		db.getConnect();
		s.setDatabase(db);
		s.setObject("10279");
		StringBuffer buffer1 =new StringBuffer("\t1.2\n\t22\n");
		s.setHeading("item.item\titem.qty");
		s.setreporton("item");
		s.setbuffer(buffer1.toString().split("\n"));
		String expected[]={"\t23.2"};
		s.getresult();
		String actual[] =s.getbuffer();
		for(int i=0;i<expected.length;i++)
		{
		System.out.println("**************************************************************************");
		System.out.println("The contents of expectedBuffer:: ");
	    System.out.println(expected.toString());
	    System.out.println("**************************************************************************");
	    System.out.println("The contents of actualbuffer:: ");
	    System.out.println(actual.toString()); 
	    System.out.println("**************************************************************************");
		}
		for(int i=0;i<actual.length;i++)
		{	System.out.println(actual[i]);
			assertEquals(expected[i], actual[i]);
		}
		
	}
	/**
	 *testZeroIntegerSum() This method is used to perform the sum operation on a both  integer values in which one value is zero
	 *
	 */
	public void testZeroIntegerSum()
	{	Sum s=new Sum();
		DBManager db=new DBManager();
		db.getConnect();
		s.setDatabase(db);
		s.setObject("10279");
		StringBuffer buffer1 =new StringBuffer("\t4444\n\t000\n");
		s.setHeading("item.item\titem.qty");
		s.setreporton("item");
		s.setbuffer(buffer1.toString().split("\n"));
		String expected[]={"\t4444.0"};
		s.getresult();
		String actual[] =s.getbuffer();
		for(int i=0;i<expected.length;i++)
		{
		System.out.println("**************************************************************************");
		System.out.println("The contents of expectedBuffer:: ");
	    System.out.println(expected.toString());
	    System.out.println("**************************************************************************");
	    System.out.println("The contents of actualbuffer:: ");
	    System.out.println(actual.toString()); 
	    System.out.println("**************************************************************************");
		}
		for(int i=0;i<actual.length;i++)
		{	System.out.println(actual[i]);
			assertEquals(expected[i], actual[i]);
		}
		
	}
	/**
	 *testOnlyZeroSum() This method is used to perform the sum operation on a both  float values in which specified value is zero
	 *
	 */
	public void testOnlyZeroSum()
	{	Sum s=new Sum();
		DBManager db=new DBManager();
		db.getConnect();
		s.setDatabase(db);
		s.setObject("10279");
		StringBuffer buffer1 =new StringBuffer("\t0.000\n\t000.00\n");
		s.setHeading("item.item\titem.qty");
		s.setreporton("item");
		s.setbuffer(buffer1.toString().split("\n"));
		String expected[]={"\t0.0"};
		s.getresult();
		String actual[] =s.getbuffer();
		for(int i=0;i<expected.length;i++)
		{
		System.out.println("**************************************************************************");
		System.out.println("The contents of expectedBuffer:: ");
	    System.out.println(expected.toString());
	    System.out.println("**************************************************************************");
	    System.out.println("The contents of actualbuffer:: ");
	    System.out.println(actual.toString()); 
	    System.out.println("**************************************************************************");
		}
		for(int i=0;i<actual.length;i++)
		{	System.out.println(actual[i]);
			assertEquals(expected[i], actual[i]);
		}
	}
	/**
	 * testOnlyZeroSum2() This method is used to perform the sum operation on a both  float values in which specified value is zero with different combination of a fields
	 *
	 */
	public void testOnlyZeroSum2()
	{	Sum s=new Sum();
		DBManager db=new DBManager();
		db.getConnect();
		s.setDatabase(db);
		s.setObject("10279");
		StringBuffer buffer1 =new StringBuffer("xyz\t0.000\nabc\t000.00\n");
		s.setHeading("item.item\titem.qty");
		s.setreporton("item");
		s.setbuffer(buffer1.toString().split("\n"));
		String expected[]={"xyz\t0.0"};
		s.getresult();
		String actual[] =s.getbuffer();
		for(int i=0;i<expected.length;i++)
		{
		System.out.println("**************************************************************************");
		System.out.println("The contents of expectedBuffer:: ");
	    System.out.println(expected.toString());
	    System.out.println("**************************************************************************");
	    System.out.println("The contents of actualbuffer:: ");
	    System.out.println(actual.toString()); 
	    System.out.println("**************************************************************************");
		}
		for(int i=0;i<actual.length;i++)
		{	System.out.println(actual[i]);
			assertEquals(expected[i], actual[i]);
		}
	}
	/**
	 * testSpecialchar1() This method is used to perform the sum operation on a integer values with different combination of a fields like special character is used
	 *
	 */
	public void testSpecialchar1()
	{	Sum s=new Sum();
		DBManager db=new DBManager();
		db.getConnect();
		s.setDatabase(db);
		s.setObject("10279");
		StringBuffer buffer1 =new StringBuffer("###\t-1\n@@@\t00\n");
		s.setHeading("item.item\titem.qty");
		s.setreporton("item");
		s.setbuffer(buffer1.toString().split("\n"));
		String expected[]={"###\t-1.0"};
		s.getresult();
		String actual[] =s.getbuffer();
		for(int i=0;i<expected.length;i++)
		{
		System.out.println("**************************************************************************");
		System.out.println("The contents of expectedBuffer:: ");
	    System.out.println(expected.toString());
	    System.out.println("**************************************************************************");
	    System.out.println("The contents of actualbuffer:: ");
	    System.out.println(actual.toString()); 
	    System.out.println("**************************************************************************");
		}
		for(int i=0;i<actual.length;i++)
		{	System.out.println(actual[i]);
			assertEquals(expected[i], actual[i]);
		}
	}
	/**
	 * testMinusFloat1() This method is used to perform the sum operation on a both  float negative values 
	 */
	public void testMinusFloat1()
	{	Sum s=new Sum();
		DBManager db=new DBManager();
		db.getConnect();
		s.setDatabase(db);
		s.setObject("10279");
		StringBuffer buffer1 =new StringBuffer("pqr\t-1.1\nyyy\t-2.1\n");
		s.setHeading("item.item\titem.qty");
		s.setreporton("item");
		s.setbuffer(buffer1.toString().split("\n"));
		String expected[]={"pqr\t-3.2"};
		s.getresult();
		String actual[] =s.getbuffer();
		for(int i=0;i<expected.length;i++)
		{
		System.out.println("**************************************************************************");
		System.out.println("The contents of expectedBuffer:: ");
	    System.out.println(expected.toString());
	    System.out.println("**************************************************************************");
	    System.out.println("The contents of actualbuffer:: ");
	    System.out.println(actual.toString()); 
	    System.out.println("**************************************************************************");
		}
		for(int i=0;i<actual.length;i++)
		{	System.out.println(actual[i]);
			assertEquals(expected[i], actual[i]);
		}
	}
	/**
	 * testThreeItem() This method is used to perform the sum operation on a integer values with different combination of a fields like three fields are used
	 */
	public void testThreeItem()
	{	Sum s=new Sum();
		DBManager db=new DBManager();
		db.getConnect();
		s.setDatabase(db);
		s.setObject("10279");
		StringBuffer buffer1 =new StringBuffer("pqr\t10\t20\nyyy\t10\t20\n");
		s.setHeading("item.item\titem.qty");
		s.setreporton("item");
		s.setbuffer(buffer1.toString().split("\n"));
		String expected[]={"pqr\t20.0"};
		s.getresult();
		String actual[] =s.getbuffer();
		for(int i=0;i<expected.length;i++)
		{
		System.out.println("**************************************************************************");
		System.out.println("The contents of expectedBuffer:: ");
	    System.out.println(expected.toString());
	    System.out.println("**************************************************************************");
	    System.out.println("The contents of actualbuffer:: ");
	    System.out.println(actual.toString()); 
	    System.out.println("**************************************************************************");
		}
		for(int i=0;i<actual.length;i++)
		{	System.out.println(actual[i]);
			assertEquals(expected[i], actual[i]);
		}
	}
	/**
	 * 
	* testSpecialchar() This method is used to perform the sum operation on a negative  and positive integer values 
	 */
	public void testSpecialchar()
	{	Sum s=new Sum();
		DBManager db=new DBManager();
		db.getConnect();
		s.setDatabase(db);
		s.setObject("10279");
		StringBuffer buffer1 =new StringBuffer("###\t-1\n@@@\t00\n");
		s.setHeading("item.item\titem.qty");
		s.setreporton("item");
		s.setbuffer(buffer1.toString().split("\n"));
		String expected[]={"###\t-1.0"};
		s.getresult();
		String actual[] =s.getbuffer();
		for(int i=0;i<expected.length;i++)
		{
		System.out.println("**************************************************************************");
		System.out.println("The contents of expectedBuffer:: ");
	    System.out.println(expected.toString());
	    System.out.println("**************************************************************************");
	    System.out.println("The contents of actualbuffer:: ");
	    System.out.println(actual.toString()); 
	    System.out.println("**************************************************************************");
		}
		for(int i=0;i<actual.length;i++)
		{	System.out.println(actual[i]);
			assertEquals(expected[i], actual[i]);
		}
}
	/**
	 * testMinusFloat2() This method is used to perform the sum operation on a both  float negative values 
	 */
	public void testMinusFloat2()
	{	Sum s=new Sum();
		DBManager db=new DBManager();
		db.getConnect();
		s.setDatabase(db);
		s.setObject("10279");
		StringBuffer buffer1 =new StringBuffer("pqr\t-1.1\nyyy\t-2.1\n");
		s.setHeading("item.item\titem.qty");
		s.setreporton("item");
		s.setbuffer(buffer1.toString().split("\n"));
		String expected[]={"pqr\t-3.2"};
		s.getresult();
		String actual[] =s.getbuffer();
		for(int i=0;i<expected.length;i++)
		{
		System.out.println("**************************************************************************");
		System.out.println("The contents of expectedBuffer:: ");
	    System.out.println(expected.toString());
	    System.out.println("**************************************************************************");
	    System.out.println("The contents of actualbuffer:: ");
	    System.out.println(actual.toString()); 
	    System.out.println("**************************************************************************");
		}
		for(int i=0;i<actual.length;i++)
		{	System.out.println(actual[i]);
			assertEquals(expected[i], actual[i]);
		}
	}
	/**
	 *testDecimalSum()  This method is used to perform the sum operation on a both  float values 
	 */
	public void testDecimalSum()
	{	Sum s=new Sum();
		DBManager db=new DBManager();
		db.getConnect();
		s.setDatabase(db);
		s.setObject("10279");
		StringBuffer buffer1 =new StringBuffer("aaa\t-0.000015\naaa\t0.00012\n");
		s.setHeading("item.item\titem.qty");
		s.setreporton("item");
		s.setbuffer(buffer1.toString().split("\n"));
		String expected[]={"aaa\t1.05E-4"};
		s.getresult();
		String actual[] =s.getbuffer();
		for(int i=0;i<expected.length;i++)
		{
		System.out.println("**************************************************************************");
		System.out.println("The contents of expectedBuffer:: ");
	    System.out.println(expected.toString());
	    System.out.println("**************************************************************************");
	    System.out.println("The contents of actualbuffer:: ");
	    System.out.println(actual.toString()); 
	    System.out.println("**************************************************************************");
		}
		for(int i=0;i<actual.length;i++)
		{	System.out.println(actual[i]);
			assertEquals(expected[i], actual[i]);
		}
	}
	/**
	 *testExponetialSum() This method is used to perform the sum operation on a both  exponential values 
	 */
	public void testExponetialSum()
	{	Sum s=new Sum();
		DBManager db=new DBManager();
		db.getConnect();
		s.setDatabase(db);
		s.setObject("10279");
		StringBuffer buffer1 =new StringBuffer("aaa\t1.35000000e-4\naaa\t1.05E-4\n");
		s.setHeading("item.item\titem.qty");
		s.setreporton("item");
		s.setbuffer(buffer1.toString().split("\n"));
		String expected[]={"aaa\t2.4E-4"};
		s.getresult();
		String actual[] =s.getbuffer();
		for(int i=0;i<expected.length;i++)
		{
		System.out.println("**************************************************************************");
		System.out.println("The contents of expectedBuffer:: ");
	    System.out.println(expected.toString());
	    System.out.println("**************************************************************************");
	    System.out.println("The contents of actualbuffer:: ");
	    System.out.println(actual.toString()); 
	    System.out.println("**************************************************************************");
		}
		for(int i=0;i<actual.length;i++)
		{	System.out.println(actual[i]);
			assertEquals(expected[i], actual[i]);
		}
	}
	/**
	 *testOnlySum1() This method is used to perform the sum operation on only  a  float values 
	 */
	public void testOnlySum1()
	{	Sum s=new Sum();
		DBManager db=new DBManager();
		db.getConnect();
		s.setDatabase(db);
		s.setObject("10279");
		StringBuffer buffer1 =new StringBuffer("10\t10");
		s.setHeading("item.item\titem.qty");
		s.setreporton("item");
		s.setbuffer(buffer1.toString().split("\n"));
		String expected[]={"10\t10.0"};
		s.getresult();
		String actual[] =s.getbuffer();
		for(int i=0;i<expected.length;i++)
		{
		System.out.println("**************************************************************************");
		System.out.println("The contents of expectedBuffer:: ");
	    System.out.println(expected.toString());
	    System.out.println("**************************************************************************");
	    System.out.println("The contents of actualbuffer:: ");
	    System.out.println(actual.toString()); 
	    System.out.println("**************************************************************************");
		}
		for(int i=0;i<actual.length;i++)
		{	System.out.println(actual[i]);
			assertEquals(expected[i], actual[i]);
		}
	}
}


